-- Decompiled with the Synapse X Luau decompiler.

local ServerOHOH = _G.ServerOHOH;
local M = ServerOHOH.class.new(script, ServerOHOH.files.Server_PlayerRankComponent(),script.Parent.Name);
local RankList = ServerOHOH.load.RankList();

-- _G.server:AddComponent(require(script.rank_view_ctrl)); --添加排行榜显示控制器

_G.server:AddComponent(require(script.rank_view_ctrl)); --添加排行榜显示控制器

function M.new(self)
	return M(self);
end;

local Server_RankManager = ServerOHOH.load.Server_RankManager();

function M.ctor(self, parent)

	M.super.ctor(self, parent);

	for k,v in pairs(RankList) do
		local s, value = Server_RankManager:GetRankValue(k, self.parent:GetUserId());
		if not s then
			self[k] = 0;
			continue;
		end;
		self[k] = value or 0;
	end
	self.DataBase= self.parent:GetComponent(ServerOHOH.load.Server_PlayerDataComponent());
	assert(self.DataBase,"self.DataBase==null")
	self.StartTime = self.DataBase:GetData("startTime");
	
	self:AddProcess(function()
		self:Wait(10)
		self:Update()
		self:AddUpdate(self.Update, 60);
	end);

end;

function M.dtor(self)
	M.super.dtor(self);
end;

local DefaultPlayerData = ServerOHOH.load.PlayerData();

function M.SaveRankBaseData(self,key, value)
	if DefaultPlayerData.isTest then
		return
	end
	value = math.ceil(value);
	
	self:SetValue(key, function()
		return value;
	end);

end;

function M.SaveRankIncrementData(self,key, value)
	if DefaultPlayerData.isTest then
		return
	end
	
	if value  then
		self:Increment(key,value)
		-- self[key]=self[key]+value
	end
end;

function M.Update(self)

	local elo=self.DataBase:GetData("base").elo
	local rolls=self.DataBase:GetData("statistics").rolls
	local challenger=self.DataBase:GetData("statistics").challenger
	local sponsor=self.DataBase:GetData("statistics").sponsor

	self:SaveRankBaseData("elo",elo)
	self:SaveRankBaseData("rolls",rolls)
	self:SaveRankBaseData("challenger",challenger)
	self:SaveRankBaseData("sponsor",sponsor)
	self:SaveRankBaseData("time",os.time()-self.StartTime)

	-- print("------------ 设置排行榜数据--------------")
end;


return M;
